package com.qfmy.webapp.controller.novel;

import com.qfmy.common.result.Result;
import com.qfmy.model.entity.novel.Chapter;
import com.qfmy.webapp.service.novel.ChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 清风明月
 * @Package com.qfmy.web.app.controller.novel
 * @date 2025/11/13
 * @description 小说章节表
 */
@RestController
@RequestMapping("/app/chapter")
public class ChapterController {

    /**
     * 注入service
     */
    @Autowired
    private ChapterService chapterService;

    /**
     * 根据小说id获取章节列表
     */
    @RequestMapping("/getChaptersByNovelId")
    public Result<List<Chapter>> getChaptersByNovelId(@RequestParam Integer novelId) {
        List<Chapter> list = chapterService.getChaptersByNovelId(novelId);
        return Result.ok(list);
    }

    /**
     * 获取章节详情
     */
    @RequestMapping("/getChapterDetail")
    public Result<List<Chapter>> getChapterDetail(@RequestParam Integer novelId) {
        List<Chapter> list = chapterService.getChapterDetail(novelId);
        return Result.ok(list);
    }

    /**
     * 根据小说id + 章节序号获取章节详情
     */
    @RequestMapping("/getChapterDetailByIndex")
    public Result<Chapter> getChapterDetailByIndex(@RequestParam Integer novelId, @RequestParam Integer chapterIndex) {
        Chapter chapter = chapterService.getChapterDetailByIndex(novelId, chapterIndex);
        return Result.ok(chapter);
    }

    /**
     * 分页获取章节数据
     */
    @RequestMapping("/getChapterList")
    public Result<List<Chapter>> getChapterList(@RequestParam Integer novelId, @RequestParam Integer pageNum, @RequestParam Integer size) {
        List<Chapter> list = chapterService.getChapterList(novelId,pageNum,size);
        return Result.ok(list);
    }


}
